#ifndef UI_INFO_H
#define UI_INFO_H

#include "Common/singleton.h"
#include "Lib2D/UIConst.h"

namespace Resolution
{
	enum
	{
		IPHONE_PORTRAIT = 0,
		IPHONE_LANDSCAPE,
		IPHONE_LANDSCAPE_HD,
		IPHONE_PORTRAIT_HD,
		IPAD_1024X768_4X3,
		IPAD_640X480_4X3,
	};

	enum
	{
		Rate3x2 = 0,
		Rate4x3,
		Rate16x9,
		Rate_MAX,
	};
}

typedef struct tgUIItem
{	
	int m_posX;
	int m_posY;	
	int m_upperLeftX;
	int m_upperLeftY;
	int m_lowerRightX;
	int m_lowerRightY;
}UI_ITEM;

typedef struct tgUISprite
{	
	const char* m_spriteName;	
	bool m_isFrame;
	int m_id;	
}UI_SPRITE;

#define UI_X(x) ((x) * UIInfo::instance()->GetScaleRateX() )
#define UI_Y(y) ((y) * UIInfo::instance()->GetScaleRateY() )
//we can multiply the reciprocal
//#define UI_SCALED_2_ORI_X(x)	((x)/UIInfo::instance()->GetScaleRateX())
//#define UI_SCALED_2_ORI_Y(y)	((y)/UIInfo::instance()->GetScaleRateY())


class gxGameState;
class UIInfo : public Singleton<UIInfo>
{
public:
	UIInfo();
	~UIInfo();

	int GetResolution();
	void SetResolution( int resol );	

	int GetRateOfResolution();
	void SetRateOfResolution(int rate);

	void SetScreenInfo( float x, float y, float w, float h);

	//Get position and touch area
	UI_ITEM *GetUIItem( int flag );

	//Get info of sprite by flag;
	UI_SPRITE *GetUISprite( int flag );

	//Get width and height of screen
	int GetScrW();
	int GetScrH();

	float GetScaleRateX();
	float GetScaleRateY();

	wchar_t *GetResolutionStr();

	void NotifyChange();
	void RegisterStateChange( gxGameState *pState );
	void UnregisterStateChange( gxGameState *pState );

	void ParseResolutionStr(char *str);

	int GetConstPostionX(int flag);
	int GetConstPostionY(int flag);
	
	int GetUI_SCALED_2_ORI_X(int x);
	int GetUI_SCALED_2_ORI_Y(int y);

	void SetIPadDevice(bool b );
	bool IsIPadDevice();
private:
	int m_resolution;
	int m_rate;	

	float m_screenX;
	float m_screenY;
	float m_screenWidth;
	float m_screenHeight;

private:
	void ChangeResolutionFromScreenInfo();
	void CreateAllItems();	

	float EnlargeRateX(int resulotion);
	float EnlargeRateY(int resulotion);
private:
	void ClearAllItems();

private:
	irr::core::array<gxGameState *> m_notifyList;
private:
	bool m_isPad;
};

#endif//UI_INFO_H